<template>
	<view>
		<!-- <u-navbar :is-back="false" title="设置" title-color="#ffffff" :background="background"></u-navbar> -->
		<view class="content">
			<u-gap height="24" bg-color="#f3f4f6"></u-gap>
			<u-cell-group>
				<u-cell-item title="清理缓存信息" @click="clear"></u-cell-item>
				<u-cell-item title="关于我们"></u-cell-item>
				<u-cell-item title="版本信息" :value="version" :arrow="false"></u-cell-item>
			</u-cell-group>
			<u-gap height="24" bg-color="#f3f4f6"></u-gap>
			<view @click="logout" class="button">退出账号</view>
			<view><u-toast ref="uToast" /></view>
		</view>
	</view>
</template>
<script>
	
export default {
	data() {
		return {
			background: {
				backgroundImage: 'linear-gradient(90deg, rgb(0,164,133), rgb(51,241,205))'
			},
			version:''
		};
	},
	onLoad(option) {
		try {
			const token = uni.getStorageSync('token');
			if (token) {
				console.log(option);
				this.userInfo = uni.getStorageSync('userInfo');
				if(!this.userInfo){
					//#ifdef APP-PLUS
					uni.reLaunch({
						url: '/pages/login/index'
					});
					//#endif
					//#ifdef MP-WEIXIN
					uni.reLaunch({
						url: '/pages/login/xcxLogin'
					});
					//#endif
				}
				this.version = plus.runtime.version
			} else {
				//#ifdef APP-PLUS
				uni.reLaunch({
					url: '/pages/login/index'
				});
				//#endif
				//#ifdef MP-WEIXIN
				uni.reLaunch({
					url: '/pages/login/xcxLogin'
				});
				//#endif
			}
		} catch (e) {
			// error
		}
	},
	onShow() {},
	methods: {
		logout() {
			this.$u.api.logout().then(res => {
				console.log('logout');
				console.log(res.statusCode);
				if (res.statusCode == 200) {
					try {
						uni.removeStorageSync('token');
						uni.removeStorageSync('userInfo');
						uni.clearStorageSync();
						//#ifdef APP-PLUS
						uni.reLaunch({
							url: '/pages/login/index'
						});
						//#endif
						//#ifdef MP-WEIXIN
						uni.reLaunch({
							url: '/pages/login/xcxLogin'
						});
						//#endif
					} catch (e) {
						// error
					}
				} else {
					this.$refs.uToast.show({
						title: '提示：退出登录失败',
						type: 'default'
					});
				}
			});
		},
		clear() {
			this.$u.api.getAuthInfo().then(res => {
				console.log(res);
				try {
					uni.removeStorageSync('userInfo');
					uni.setStorageSync('userInfo', res.data.user.user);
				} catch (e) {
					// error
				}
				this.$refs.uToast.show({
					title: '提示：清理缓存成功',
					type: 'success'
				});
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: $u-bg-color;
}
.content {
	.button {
		background-color: #ffffff;
		padding: 24rpx 32rpx;
		text-align: center;
		color: $u-type-success;
	}
}
</style>
